<?php
/*
	批量生成防伪码
	参数
		$security_code		防伪码

	返回值
		布尔值，真表示有效，假表示无效
*/
defined('BY_JYA') or exit('error');
list($security_code)=$arguments;
$setting=$this->plugin_setting('secury');//获取参数设置
$start=strlen($setting['pre']);
$goods_code=intval(substr($security_code,$start,$setting['goods']));//商品批号
$start+=$setting['goods'];
$batch_code=intval(substr($security_code,$start,$setting['batch']));//防伪码批号
$start+=$setting['batch'];
$serial_code=intval(substr($security_code,$start,$setting['serial']));//流水号
$start+=$setting['serial'];
$string=substr($security_code,0,$start);//校验字符串
$check_code=intval(substr($security_code,$start,$setting['code']));//校验码
$batch=pdo_get('jy_security_batch',array('goods_code'=>$goods_code,'code'=>$batch_code,'uniacid'=>$_SESSION['uniacid']));
if(!$batch || !$batch['status'] || !$batch['num']){
	return false;
}
if($serial_code>$batch['num']){
	return false;
}
if($check_code!=cfc('tools')->create_check_code($string,$batch['seckey'],$setting['code'])){
	return false;
}
//插入查询日志
$insert=array(
	'uniacid'=>$_SESSION['uniacid'],
	'mid'=>$_SESSION['uid'],
	'goods_id'=>$batch['goods_id'],
	'batch_id'=>$batch['batch_id'],
	'code'=>$security_code,
	'createtime'=>TIMESTAMP,
);
pdo_insert('jy_security_log',$insert);
$id=pdo_insertid();
return $id;